<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var arr1 = [5, 4, 3, 2, 1, 6, 2, 4];
        var arr2 = [2, 412, 52, 211, 45, 6];

        function sort(arr) {
            var temp = 0;

            // 要按从小到大排序
            for (var i = 1; i < arr.length; i++) {
                for (var j = 0; j <= arr.length - i; j++) {
                    if (arr[j] > arr[j + 1]) {
                        temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
            return arr;
        }
        console.log(sort(arr1));
        console.log(sort(arr2));
    </script>
</head>

<body>

</body>

</html>